package com.guhappy.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.guhappy.action.model.ChartPageBean;
import com.guhappy.action.model.PieChartPageBean;
import com.guhappy.model.user.StockPriceHistrHome;
import com.opensymphony.xwork2.ActionSupport;

public class JsonCharts extends ActionSupport implements SessionAware {
	private static final Log log = LogFactory.getLog(JsonRollingBarBean.class);

	private String area;
	private String stockID;
	private List priceList;
	private int min;
	private int max;
	private int step;
	private PieChartPageBean bBean;
	private SessionMap<String, String> myMap;

	public String execute() throws Exception {
		return SUCCESS;
	}

	public String listPrice() {
		log.info("build json price list includeing area : " + area);
		
		if(stockID !=null && !stockID.trim().equals("")){
			ChartPageBean aBean = StockPriceHistrHome.getPriceList(stockID);

			priceList = aBean.getListPrice();
			min = aBean.getMin();
			max = aBean.getMax();
			step = aBean.getStep();
			bBean = StockPriceHistrHome.getPieInfo(stockID, myMap.get(area) );
		}
		return SUCCESS;
	}

	public PieChartPageBean getbBean() {
		return bBean;
	}

	public void setbBean(PieChartPageBean bBean) {
		this.bBean = bBean;
	}

	public String getJSON() {
		return listPrice();
	}

	public String getStockID() {
		return stockID;
	}

	public void setStockID(String stockID) {
		this.stockID = stockID;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getArea() {
		return area;
	}

	public List getPriceList() {
		return priceList;
	}

	public void setPriceList(List priceList) {
		this.priceList = priceList;
	}

	public int getMin() {
		return min;
	}

	public int getMax() {
		return max;
	}

	public int getStep() {
		return step;
	}

	public void setSession(Map<String, Object> session) {
		myMap = (SessionMap) session;
		myMap.put("United States", "4028b88148ba822a0148ba822acc0000");
		myMap.put("Canada", "2");
		myMap.put("North America", "3");
		myMap.put("China", "4028b8814ad58b64014ad58b65770000");
		myMap.put("Hongkong", "5");
		myMap.put("Taiwan", "6");
		myMap.put("Singapore", "7");
		myMap.put("Austrilia", "8");
		myMap.put("London", "9");
		myMap.put("Korea", "10");
	}

}
